package com.ss.android.account.v2.c;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;

import com.bytedance.common.utility.collection.WeakHandler;
import com.ss.android.account.Spipe;
import com.ss.android.account.activity.AuthorizeActivity;
import com.ss.android.account.b.OnAccountRefreshListener;
import com.ss.android.account.bus.event.d;
import com.ss.android.account.bus.event.e;
import com.ss.android.account.bus.event.g;
import com.ss.android.account.d.b;
import com.ss.android.account.e.h;
import com.ss.android.account.v2.b.f;
import com.ss.android.messagebus.SubscriptionRouter;

public abstract class a extends com.ss.android.account.d.b implements OnAccountRefreshListener, h {
    protected com.ss.android.account.v2.b.a c;
    protected String d;
    private boolean e;
    private Spipe f;
    private String g;
    private f h;

    public a(Context arg2) {
        super(arg2);
        this.e = true;
        this.f = Spipe.inst();
        this.c = new com.ss.android.account.v2.b.a(arg2);
    }

    public final void a(int arg2, int arg3, Intent arg4) {
        super.a(arg2, arg3, arg4);
        if(arg2 == 100 && arg3 == 0) {
            this.f.b(((OnAccountRefreshListener)this));
        }
    }

    public void a(Bundle arg3, Bundle arg4) {
        String v0_1;
        if(arg3 != null) {
            v0_1 = arg3.getString("extra_mobile_num");
        }
        else {
            v0_1 = null;
        }

        String v1 = TextUtils.isEmpty(v0_1) ? android.support.design.a.k(this.b) : v0_1;
        if(!TextUtils.isEmpty(v1) && (this.c())) {
            ((com.ss.android.account.d.d)this.a).b(v1);
        }

        if(arg3 != null) {
            this.d = arg3.getString("extra_source");
        }
    }

    public void a(String arg4) {
        this.f.addOnAccountRefreshListener(((OnAccountRefreshListener)this));
        Intent v1 = new Intent(((b)this).b, AuthorizeActivity.class);
        v1.putExtra("platform", arg4);
        if(this.c()) {
            ((com.ss.android.account.d.d)this.a).startActivityForResult(v1, 100);
        }

        this.g = arg4;
    }

    protected abstract void a(String arg1, int arg2, String arg3, Object arg4);

    final void a(String arg4, com.ss.android.account.b.k.k$a arg5) {
        this.e = false;
        com.ss.android.account.bb.a().a(arg4);
        Spipe.inst().a(Message.obtain(this.d(), 1001, arg5));
        if(arg5.l) {
            SubscriptionRouter.c(new e());
            this.b("profile_settings_show");
        }
        else {
            SubscriptionRouter.c(new d(true));
        }
    }

    protected final void a(String arg5, String arg6) {
        this.g = "";
        if(this.c()) {
            ((com.ss.android.account.d.d)this.a).c();
        }

        this.h = new com.ss.android.account.v2.c.b(this, arg5);
        com.ss.android.account.v2.b.a v0 = this.c;
        com.ss.android.account.v2.b.d v2 = new com.ss.android.account.v2.b.d(v0, this.h);
        if(v0.a(((WeakHandler.Callback)v2))) {
            new com.ss.android.account.activity.mobile.d.d$d((Context) v0.a.a.get(), new WeakHandler(Looper.getMainLooper(), ((WeakHandler.Callback)v2)), com.ss.android.account.v2.b.a.a(arg5), arg6).start();
        }
    }

    public final void b(String arg3) {
        android.support.design.a.a(((b)this).b, arg3, this.d);
    }

    public void b() {
        super.b();
        this.e();
        this.f.b(((OnAccountRefreshListener)this));
    }

    public void e() {
        if(this.h != null) {
            this.h.a = true;
            this.h = null;
        }
    }

    protected final void f() {
        String v0 = "";
        if("qzone_sns".equals(this.g)) {
            v0 = "mobile_login_success_qq";
        }
        else if("renren_sns".equals(this.g)) {
            v0 = "mobile_login_success_renren";
        }
        else if("qq_weibo".equals(this.g)) {
            v0 = "mobile_login_success_qqweibo";
        }
        else if("sina_weibo".equals(this.g)) {
            v0 = "mobile_login_success_sinaweibo";
        }
        else if("weixin".equals(this.g)) {
            v0 = "mobile_login_success_weixin";
        }
        else if("flyme".equals(this.g)) {
            v0 = "mobile_login_flyme";
        }
        else if("huawei".equals(this.g)) {
            v0 = "mobile_login_huawei";
        }
        else if("telecom".equals(this.g)) {
            v0 = "mobile_login_click_telecom";
        }

        if(!android.support.design.a.isTextEmpty(v0)) {
            this.b(v0);
        }
    }

    protected abstract void g();

    public void onAccountRefresh(boolean arg3, int arg4) {
        if((arg3) && (this.e)) {
            SubscriptionRouter.c(new d(false));
            SubscriptionRouter.c(new g());
        }
    }
}

